import { ethers } from "ethers";
import ABI from "../abis/cUSDT.json";
import { SEPOLIA_NET } from "../const/contractAddress.js";

let provider = new ethers.BrowserProvider(window.ethereum);
const contractAddress = SEPOLIA_NET.erc20;

export async function approve(spender, amount) {
  const contract = new ethers.Contract(
    contractAddress,
    ABI,
    await provider.getSigner()
  );
  const result = await contract.approve(spender, amount);
  console.log(result.hash);
}

export async function getAllowance(owner, spender) {
  const contract = new ethers.Contract(
    contractAddress,
    ABI,
    await provider.getSigner()
  );
  const result = await contract.allowance(owner, spender);
  return Number(result);
}
export async function mint(to, amount) {
  const singer = new ethers.Wallet();
  const contract = new ethers.Contract(
    contractAddress,
    ABI,
    await provider.getSigner()
  );
  const result = await contract.transferFrom(
    SEPOLIA_NET.managerAddress,
    to,
    amount
  );
  console.log(result.hash);
}
export async function getBalance(address) {
  const contract = new ethers.Contract(
    contractAddress,
    ABI,
    await provider.getSigner()
  );
  const result = await contract.balanceOf(address);
  return Number(result);
}
